package com.gqb.spring.framework;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.apache.commons.lang.StringUtils;

import com.gqb.spring.tag.Bean;

public class InitializingBeanProcessor {
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public  static void Process(Object object,Bean bean,Class clazz) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException{
		if(null!=object){
			if(null!=bean){//实在xml配置了 初始化的方法，也可能是通过继承InitializingBean 来实现初始化
				Class clazzClass=Class.forName(bean.getClassName());
				if(!StringUtils.isEmpty(bean.getInitMethodName())){
					Method method=clazzClass.getMethod(bean.getInitMethodName(), null);
					method.invoke(object, null);
				}
				if(!StringUtils.isEmpty(bean.getDestroyMethodName())){
					Method destroyMethod=clazzClass.getMethod(bean.getDestroyMethodName(), null);
					destroyMethod.invoke(object, null);
				}
			}
			if(null!=clazz){//通过annotation的方式来指定初始化的方法
				
			}
		}
	}
}
